<?php
namespace app\admin\controller;

use app\admin\code\BaseCode;
use app\admin\logic\LoginLogic;
use app\admin\util\Response;
use think\Image;
use think\Lang;
use think\Request;
use think\Session;

class Util
{
    public function upload(){
        $path = ROOT_PATH . 'public' . DS . 'uploads';
        $file = Request::instance()->file('file');
        if(isset($file)){
            $info = $file->move($path);
            if($info){
                $url = DS.'uploads'.DS.$info->getSaveName();
                Response::json(BaseCode::SUCCESS,Lang::get(BaseCode::SUCCESS),['url'=>$url]);
            }else{
                Response::json(BaseCode::UPLOAD_ERROR,$file->getError());
            }

        }else{
            Response::json(BaseCode::UPLOAD_ERROR,Lang::get(BaseCode::UPLOAD_ERROR));
        }
    }
}
